using UnityEngine;
using System.Collections;

public class HUD : MonoBehaviour {
	
	public Texture2D foto;
	string pokemon = "";
	public Texture2D vida;
	public int maxHealth = 100; 
	public int curhealth;
	public float healthBarLenght;
	public PokeBehave PokAtivo;
	
	bool selecionado = false;
	
	
	//public GameObject monstro;
	
	GUIStyle style = new GUIStyle();
	
	// Use this for initialization
	void Start () {
		healthBarLenght = Screen.width / 2;
	}
	
	// Update is called once per frame
	void Update () 
	{
		AddjustCurrentHealth();
		
		if(Input.GetKeyDown(KeyCode.Q))
		{
			selecionar(selecionado);
		}
		if(Input.GetKeyDown(KeyCode.Z) && PokAtivo.atqs[0].cd == PokAtivo.atqs[0].cooldown)
		{
			PokAtivo.Atacar(PokAtivo.atqs[0].name);
			PokAtivo.atqs[0].cd = 0;
		}
	}
	
	void OnGUI()
	{
		if (pokemon == "")
		{
			GUI.Box(new Rect(10,10,100,90),"");
			GUI.Box(new Rect(10,105,100,20),"Pressione 'Q'"); 
		}
		else if(pokemon == "Bulbasauro")
		{
			GUI.Box(new Rect(10,10,100,90),foto);
			GUI.Box(new Rect(10,105,100,20),pokemon); 
			//GUI.Box(new Rect(120,10,100,20),vida);
			style.normal.background = vida;
			style.alignment = TextAnchor.MiddleCenter;
			GUI.Box(new Rect(120, 10, healthBarLenght, 20), (curhealth + "/" + maxHealth),style);
			for(int i = 0; i < 4; i++){
				if(PokAtivo.atqs[i].name != ""){
					GUI.Box(new Rect(10, 135+(35*i), 120, 20), PokAtivo.atqs[i].name);
					GUI.Box(new Rect(10, 155+(35*i), (PokAtivo.atqs[i].cd*120)/PokAtivo.atqs[i].cooldown, 10), PokAtivo.atqs[i].cd.ToString(), style);
				}else{
					GUI.Box(new Rect(10, 135+(35*i), 120, 20), "--empty--");
				}
			}
			
			//vida.width = 200;
		}
	}
	
	void selecionar (bool selecao)
	{
		if(selecao)
		{
			pokemon = "";
			PokAtivo.ativo = false;
			selecionado = false;
		}
		else
		{
			pokemon = "Bulbasauro";
			PokAtivo.ativo = true;
			selecionado = true;	
		}
	}
		
	
	
	public void AddjustCurrentHealth() 
	{
		if(curhealth > 20)
		{
   	 		healthBarLenght = (Screen.width / 4) * (curhealth / (float)maxHealth);
		}
		else
		{
			healthBarLenght = 60;
		}
	}
		
}
